﻿<%@ WebHandler Language="C#" Class="InputCheckPointResultVue3PageHandler" %>

/* Description:实测值录入
 * Copyright (c) : 通力凯顿（北京）系统集成有限公司
 * Writer:zhunan 
 * create Date:2024.8.23
 */

using System;
using System.Net;
using System.IO;
using System.Web;
using System.Linq;
using System.Configuration;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using BusinessRule.DTO;
using DatabaseAccess.DBUtility;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;
using BusinessRule.Common;
using NPOI.SS.UserModel;

public class InputCheckPointResultVue3PageHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    uLMSCommonIBusiness m_Common = uMESBusinessFactory.instance.GetuLMSCommonObject();
    uLMSContainerInStoreIBusiness m_ContainerData = uMESBusinessFactory.instance.GetuLMSContainerInStoreObject();
    uLMSStepCheckPointIBusiness m_CheckPointObj = uMESBusinessFactory.instance.GetuLMSStepCheckPointObject();
    uLMSCommonBusiness m_CommonObj = new uLMSCommonBusiness();
    string usingImg = ConfigurationManager.AppSettings["UsingCheckImageSavePath"];
    bool isUseIP = ConfigurationManager.AppSettings["IsUseIP"] == "1" ? true : false;
    string importPath = ConfigurationManager.AppSettings["ImportPath"]; //导入路径
    string exportPath = ConfigurationManager.AppSettings["ExportPath"]; //导出路径
    CurrentUserInfo m_UserInfo = new CurrentUserInfo();
    public bool IsReusable { get { return false; } }
    String GetCode(DataTable dtImage, string strCode)
    {
        String strHtmlCode, strHtml, strHtmlTemp;
        try
        {
            int i, intStartFlag, intEndFlag;
            strHtml = strCode;
            strHtmlCode = strHtml;
            intStartFlag = strHtmlCode.IndexOf("<img");
            if (intStartFlag == -1)
            {
                intStartFlag = strHtmlCode.IndexOf("<IMG");
            }
            if (intStartFlag > -1)
            {
                intEndFlag = strHtmlCode.IndexOf(">", intStartFlag);
            }
            else
            {
                intEndFlag = -1;
            }

            if (dtImage != null)
            {
                if (dtImage.Rows.Count > 0)
                {
                    while (intStartFlag > -1)
                    {
                        strHtmlTemp = strHtmlCode.Substring(intStartFlag, intEndFlag - intStartFlag + 1);
                        for (i = 0; i <= dtImage.Rows.Count - 1; i++)
                        {
                            if (strHtmlTemp.IndexOf(@"/" + dtImage.Rows[i][0]) > -1)
                            {
                                strHtmlCode = strHtmlCode.Replace(strHtmlTemp, (String)dtImage.Rows[i][1]);
                                break;
                            }

                        }

                        intStartFlag = strHtmlCode.IndexOf("<img", intStartFlag + 1);
                        if (intStartFlag == -1)
                        {
                            intStartFlag = strHtmlCode.IndexOf("<IMG", intStartFlag + 1);
                        }
                        if (intStartFlag > -1)
                        {
                            intEndFlag = strHtmlCode.IndexOf(">", intStartFlag + 1);
                            ;
                        }
                        else
                        {
                            intEndFlag = -1;
                        }
                    }
                }
            }

            return strHtmlCode;
        }
        catch (Exception myError)
        {
            return "";
        }
    }

    //获取检测值
    string GetCheckPointNote(HttpContext context, string note)
    {
        uLMS_CommonFunction common = new uLMS_CommonFunction();
        if (note.Contains("<img"))
        {
            List<object> para = new List<object>();
            string[] sp = Regex.Split(note, "<img src=\"", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            foreach (string item in sp)
            {
                if (item.Contains("\\UsingCheckImage\\"))
                {
                    string[] sps = Regex.Split(item, "\">", RegexOptions.IgnoreCase);
                    string imgPath = context.Server.MapPath(sps[0]);
                    Bitmap bitmapImage = new Bitmap(imgPath);
                    para.Add(bitmapImage);
                    if (sps.Length > 1)
                    {
                        para.Add(sps[1]);
                    }
                }
                else
                {
                    para.Add(item);
                }
            }
            return common.MerageImagsAndStrs(para, 0);
        }
        return note;
    }

    void DeleteUploadedFile(string filePath)
    {
        if (File.Exists(filePath))
        {
            FileInfo fileinfo = new FileInfo(filePath);
            fileinfo.Attributes = FileAttributes.Normal;
            File.Delete(filePath);
        }
    }

    public void ProcessRequest(HttpContext context)
    {
        var actions = context.Request.QueryString["actions"];
        //导入检测项(检验)
        if (actions != null && actions.ToString() == "importCheckPointItem")
        {
            try
            {
                context.Response.ContentType = "application/json";
                uMESProcessResult r = importCheckPointItem(context);//导入检测项(检验)
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
            catch (Exception e)
            {
                uMESProcessResult r = new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "500", Message = e.Message };
                context.Response.ContentType = "text/json";
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
        }
        else if (actions != null && actions.ToString() == "importWorkerCheckPointItem")//导入检测项(工人)
        {
            try
            {
                context.Response.ContentType = "application/json";
                uMESProcessResult r = importWorkerCheckPointItem(context);//导入检测项(工人)
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
            catch (Exception e)
            {
                uMESProcessResult r = new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "500", Message = e.Message };
                context.Response.ContentType = "text/json";
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
        }
        else if (actions != null && actions.ToString() == "uploadFile")//上传实测值附件
        {
            try
            {
                context.Response.ContentType = "application/json";
                uMESProcessResult r = saveCheckPointResultDocFile(context);//上传实测值附件
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
            catch (Exception e)
            {
                uMESProcessResult r = new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "500", Message = e.Message };
                context.Response.ContentType = "text/json";
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
        }
        else
        {
            string requestjson = "";
            using (System.IO.StreamReader reader = new StreamReader(context.Request.InputStream)) { requestjson = reader.ReadToEnd(); }
            JObject jObject = JsonConvert.DeserializeObject(requestjson) as JObject;
            if (jObject["type"] != null)
            {
                try
                {
                    uMESProcessResult r = new uMESProcessResult();
                    context.Response.ContentType = "text/json";
                    string type = jObject["type"].ToString();
                    switch (type)
                    {
                        case "getContainerDataList":
                            r = getContainerDataList(jObject);
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "getCheckItemList":
                            r = getCheckItemList(jObject);//获取检测项
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "getStepCheckPointResult":
                            r = getStepCheckPointResult(jObject, context);//查询检测项录入结果
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "saveCheckResultByCheck":
                            r = saveCheckResultByCheck(jObject, context);//保存实测值（检验）
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "deleteCheckPointResult":
                            r = deleteCheckPointResult(jObject);//删除实测值（工人、检验）
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "exportCheckPointItem":
                            r = exportCheckPointItem(jObject, context);//导出检测项(检验)
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "copyWorkerInputResultValue":
                            r = copyWorkerInputResultValue(jObject);//一键确认（复制工人检测内容）
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "sendToThreeCoordinateRecord":
                            r = sendToThreeCoordinateRecord(jObject);//保存推送给三坐标检测记录
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "getChildContainerList":
                            r = getChildContainerList(jObject);//获取批量带子序号批次
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "saveCheckResultByWorker":
                            r = saveCheckResultByWorker(jObject, context);//保存实测值（工人）
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "exportCheckPointFileByWorker":
                            r = exportCheckPointFileByWorker(jObject, context);//导出检测项(工人)
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "getWorkreportChildContainer":
                            r = getWorkreportChildContainer(jObject);//查询单件带子序号报工时选择的子批次
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "copyWorkerInputValidate":
                            r = copyWorkerInputValidate(jObject);//一键确认前校验
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "getWorkerInputValues":
                            r = getWorkerInputValues(jObject);//工人已录入实测值
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        case "getInputCheckPointResult":
                            r = getInputCheckPointResult(jObject);
                            context.Response.Write(JsonConvert.SerializeObject(r));
                            break;
                        default:
                            break;
                    }
                }
                catch (Exception e)
                {
                    uMESProcessResult r = new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "500", Message = e.Message };
                    context.Response.ContentType = "text/json";
                    context.Response.Write(JsonConvert.SerializeObject(r));
                }
            }
        }
    }

    //获取批量带子序号批次
    uMESProcessResult getChildContainerList(JObject obj)
    {
        DataTable dtChildContainer = m_CommonObj.GetContainerInfoByPerContianerID2(obj["containerid"].ToString());
        foreach (DataColumn col in dtChildContainer.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtChildContainer, RowCount = dtChildContainer.Rows.Count.ToString(), Code = "200", Message = "上传成功" };
    }

    uMESProcessResult getContainerDataList(JObject obj)
    {
        uMESProcessResult result = new uMESProcessResult();
        DataTable dtSession = JsonConvert.DeserializeObject<DataTable>(obj["postData"].ToString());
        if (!dtSession.Columns.Contains("StepInfoID"))
        {
            dtSession.Columns.Add("StepInfoID");//如果没有工步，加一个空值，防止后续报错
            dtSession.Columns.Add("StepInfoName");
        }
        var type = obj["type"].ToString();
        var ContainerID = string.Empty;
        foreach (DataRow dr in dtSession.Rows)
        {
            ContainerID += "|" + dr["ContainerID"] + "|,";
        }
        DataRow rowContianer = dtSession.Rows[0];
        Dictionary<string, string> para = new Dictionary<string, string>();
        para.Add("ContainerID", type == "2" ? ContainerID.TrimEnd(',').TrimEnd('|').TrimStart('|').Replace("|", "'") : rowContianer["ContainerID"].ToString());
        para.Add("WorkflowStepID", rowContianer["WorkflowStepID"].ToString());

        //如果包含有工步，查询工步
        if (!string.IsNullOrWhiteSpace(rowContianer["StepInfoID"].ToString()))
        {
            para.Add("StepInfoID", rowContianer["StepInfoID"].ToString());
        }
        DataTable dtReportContainer = m_CheckPointObj.GetWorkreportInfoByContainer(para);//报工批次
        foreach (DataColumn col in dtReportContainer.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        dtReportContainer.TableName = "dtReportContainer";
        result.DBDataSet.Tables.Add(dtReportContainer);
        //批次子序号
        if (rowContianer["ContainerType"].ToString() == "3")
        {
            if (string.IsNullOrWhiteSpace(rowContianer["StepInfoID"].ToString())) //如果包含工步，则不显示子序号
            {
                string sql = @"SELECT c.containerid childcontainerid,c.containername childcontainername,c.parentcontainerid containerid 
                               FROM container c 
                               WHERE c.parentcontainerid = '{0}' AND c.status =1 
                               ORDER BY c.containerid";
                DataTable dtChildContainer = DatabaseHelper.Query_ReturnDatTable(string.Format(sql, rowContianer["ContainerID"].ToString()));
                foreach (DataColumn col in dtChildContainer.Columns)
                {
                    col.ColumnName = col.ColumnName.ToLower();
                }
                dtChildContainer.TableName = "dtChildContainer";
                result.DBDataSet.Tables.Add(dtChildContainer);
            }
        }
        return new uMESProcessResult() { ReturnData = result.DBDataSet, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //查询单件带子序号报工时选择的子批次
    uMESProcessResult getWorkreportChildContainer(JObject obj)
    {
        string containerstepworkreportid = obj["containerstepworkreportid"].ToString();
        string sql = @"SELECT csd.childcontainerid FROM containerstepworkreportchild csd WHERE csd.containerstepworkreportid = '{0}'";
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(string.Format(sql, containerstepworkreportid));
        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询检测项
    uMESProcessResult getCheckItemList(JObject obj)
    {
        Dictionary<string, string> para = new Dictionary<string, string>();
        para.Add("ContainerID", obj["containerID"].ToString());
        para.Add("StepID", obj["workFlowStepId"].ToString());
        para.Add("ContainerStepWorkReportID", obj["containerStepWorkReportID"].ToString());
        para.Add("StepInfoID", obj["stepInfoID"].ToString());

        string sql = @"
SELECT sp.stepcheckpointid,sp.checktype,nvl(sp.checkpointnote,'') checkpointnote,sp.inputnum,
       nvl(sp.checkpointnotedis,'') checkpointnotedis,nvl(sp.checkpointnotedis_b,'') checkpointnotedis_b,
       spr.workcheckpointresultnotedis,ck.checkpointresultnotedis,
       sp.keycheck,sp.name,sp.DrawingRequire,sp.DrawingRequireDis,nvl(sp.DrawingRequireDis_b,'') DrawingRequireDis_b,sp.BubbleNumber,
       DECODE(sp.CHECKTYPE, '3', '设计特性', '4', '过程参数','5','振动攻关', CHECKTYPE) CHECKTYPENAME,
       DECODE(sp.KEYCHECK, '1', '是', '0', '否', KEYCHECK) KEYCHECKNAME,
       DECODE(sp.MEOPCHECK, '1', '是', '0', '否', MEOPCHECK) MEOPCHECKNAME,
       DECODE(sp.QUALITYCHECK, '1', '是', '0', '否', QUALITYCHECK) QUALITYCHECKNAME,
       DECODE(sp.TCCHECKPOINTNOTE, NULL, '否', '是') ISTCM,
       sp.basevalue,sp.ceilfloat,sp.floorfloat,sp.checkmethod,
       (SELECT COUNT(1) FROM stepcheckpointresult spr WHERE spr.stepcheckpointid = sp.stepcheckpointid AND spr.containerid = '{1}'{2}) inputcount 
FROM stepcheckpoint sp
LEFT JOIN (
    SELECT sp.stepcheckpointid,spr.containerid,spr.workcheckpointresultnotedis,
           row_number () OVER (PARTITION BY sp.stepcheckpointid,spr.containerid ORDER BY spr.lastchangedate DESC) as rn
    FROM stepcheckpoint sp
    LEFT JOIN stepcheckpointresult spr ON spr.stepcheckpointid = sp.stepcheckpointid AND spr.containerid = '{1}'
    WHERE spr.workcheckpointresultnotedis IS NOT NULL AND sp.workflowstepid = '{0}' {2}
) spr ON spr.stepcheckpointid = sp.stepcheckpointid AND spr.containerid = '{1}' AND spr.rn = 1
LEFT JOIN (
    SELECT sp.stepcheckpointid,spr.containerid,spr.checkpointresultnotedis,
           row_number () OVER (PARTITION BY sp.stepcheckpointid,spr.containerid ORDER BY spr.checkdate DESC) as rn
    FROM stepcheckpoint sp
    LEFT JOIN stepcheckpointresult spr ON spr.stepcheckpointid = sp.stepcheckpointid AND spr.containerid = '{1}'
    WHERE spr.checkdate IS NOT NULL AND sp.workflowstepid = '{0}' {2}
) ck ON ck.stepcheckpointid = sp.stepcheckpointid AND ck.containerid = '{1}' AND ck.rn = 1
WHERE sp.workflowstepid = '{0}'
ORDER BY sp.stepcheckpointid";
        sql = string.Format(sql,
                            para["StepID"],
                            para["ContainerID"],
                            para["ContainerStepWorkReportID"].ToString() != "" ? string.Format(" AND spr.containerstepworkreportid = '{0}'", para["ContainerStepWorkReportID"]) : ""
            );//如果报工ID 不为空，则统计到报工级
        if (para["StepInfoID"] != "")
        {
            sql += string.Format(" AND sp.stepinfoid = '{0}'", para["StepInfoID"]);
        }
        DataTable dtResult = UpdatePointDis(DatabaseHelper.Query_ReturnDatTable(sql));
        foreach (DataColumn col in dtResult.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtResult, RowCount = dtResult.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    DataTable UpdatePointDis(DataTable dtPoint)
    {
        foreach (DataRow item in dtPoint.Rows)
        {
            if (string.IsNullOrWhiteSpace(item["Checkpointnote"].ToString()))
            {
                continue;
            }
            ExcuteEntity exuteEntity = new ExcuteEntity("stepcheckpoint", ExcuteEntity.ExcuteTypeEnum.update);
            exuteEntity.WhereFileds = new List<FieldEntity> { new FieldEntity("stepcheckpointid", item["stepcheckpointid"].ToString(), FieldEntity.FieldTypeEnum.Str) };
            List<FieldEntity> excuteFieldList = new List<FieldEntity>();
            if (string.IsNullOrWhiteSpace(item["CheckpointnoteDis"].ToString()))
            {
                item["CheckpointnoteDis"] = m_CheckPointObj.ConvertTohtml(item["Checkpointnote"].ToString(), usingImg, isUseIP);
                excuteFieldList.Add(new FieldEntity("CheckpointnoteDis", item["CheckpointnoteDis"].ToString(), FieldEntity.FieldTypeEnum.Str));
            }
            if (!string.IsNullOrWhiteSpace(item["DrawingRequire"].ToString()) && string.IsNullOrWhiteSpace(item["DrawingRequireDis"].ToString()))
            {
                item["DrawingRequireDis"] = m_CheckPointObj.ConvertTohtml(item["DrawingRequire"].ToString(), usingImg, isUseIP);
                excuteFieldList.Add(new FieldEntity("DrawingRequireDis", item["DrawingRequireDis"].ToString(), FieldEntity.FieldTypeEnum.Str));
            }
            //更新数据库数据
            if (excuteFieldList.Count > 0)
            {
                exuteEntity.ExcuteFileds = excuteFieldList;
                DatabaseAccess.DBUtility.DatabaseHelper.ExecuteDataByEntity(exuteEntity);
            }
        }
        dtPoint.AcceptChanges();
        return dtPoint;
    }

    //查询检测项录入结果
    uMESProcessResult getStepCheckPointResult(JObject obj, HttpContext context)
    {
        DataTable dtChildContainer = JsonConvert.DeserializeObject<DataTable>(obj["childContainer"].ToString());
        string childContainerIDs = string.Empty;//子序号ID
        if (dtChildContainer.Rows.Count > 0)
        {
            dtChildContainer.AsEnumerable().ToList().ForEach(p => { childContainerIDs += string.Format("'{0}',", p["childcontainerid"].ToString()); });
        }
        string stepCheckPointID = obj["stepCheckPointId"].ToString();//检测项ID
        string containerID = obj["containerId"].ToString();//批次ID
        string containerStepWorkReportID = obj["containerStepWorkReportID"].ToString();//报工ID
        StringBuilder sql = new StringBuilder();
        sql.AppendFormat(@"SELECT spr.workcheckpointresultnote,spr.checkpointresultnote,spr.checkpointresultnotedis,spr.workcheckpointresultnotedis,spr.stepcheckpointresultid,spr.containerstepworkreportid,
                            spr.checkpointresultnotedis_b,spr.workcheckpointresultnotedis_b,nvl(spr.spcstatus,0) spcstatus,DECODE(spr.spcstatus,1,'异常','') spcstatusname,
                            e.fullname worker,em.fullname checker,c.containername childcontainername,spr.createdate,spr.checkdate,NVL(spr.workresultdocpath,'') workresultdocpath,
                            NVL(spr.checkresultdocpath,'') checkresultdocpath,'' checkresultdocname,'' workresultdocname,spr.stepcheckpointid,sc.basevalue,sc.floorfloat,sc.ceilfloat,sc.bubblenumber
                             FROM stepcheckpointresult spr 
                            LEFT JOIN employee e ON e.employeeid = spr.workerid
                            LEFT JOIN employee em ON em.employeeid = spr.checkerid
                            LEFT JOIN container c ON c.containerid = spr.childcontainerid AND c.status =1
                            LEFT JOIN stepcheckpoint sc ON sc.stepcheckpointid = spr.stepcheckpointid
                            WHERE spr.stepcheckpointid = '{0}' AND spr.containerid = '{1}'", stepCheckPointID, containerID);
        if (!string.IsNullOrWhiteSpace(childContainerIDs))
        {
            childContainerIDs = childContainerIDs.TrimEnd(',');
            sql.AppendFormat(" AND c.containerid in ({0})", childContainerIDs);
        }
        if (!string.IsNullOrWhiteSpace(containerStepWorkReportID))//报工ID 不为空
        {
            sql.AppendFormat(" AND spr.containerstepworkreportid = '{0}'", containerStepWorkReportID);
        }
        sql.Append(" ORDER BY c.containername");
        DataTable dtResult = DatabaseHelper.Query_ReturnDatTable(sql.ToString());
        foreach (DataRow item in dtResult.Rows)
        {
            if (!string.IsNullOrWhiteSpace(item["workresultdocpath"].ToString()))
            {
                item["workresultdocname"] = Path.GetFileName(item["workresultdocpath"].ToString());
                item["workresultdocpath"] = string.Format("http://{0}{1}{2}", context.Request.Url.Host, context.Request.ApplicationPath, item["workresultdocpath"].ToString());
            }
            if (!string.IsNullOrWhiteSpace(item["checkresultdocpath"].ToString()))
            {
                item["checkresultdocname"] = Path.GetFileName(item["checkresultdocpath"].ToString());
                item["checkresultdocpath"] = string.Format("http://{0}{1}{2}", context.Request.Url.Host, context.Request.ApplicationPath, item["checkresultdocpath"].ToString());
            }
        }
        foreach (DataColumn col in dtResult.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtResult, RowCount = dtResult.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //保存检验员录入的实测值
    uMESProcessResult saveCheckResultByCheck(JObject obj, HttpContext context)
    {
        DataTable dtImage = (DataTable)context.Session["dtImage"];
        string content = obj["content"].ToString();//
        CurrentUserInfo m_UserInfo = m_Common.GetUserInfo(obj["employeename"].ToString(), "");
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "保存成功" };
        DataTable dtChildContainer = JsonConvert.DeserializeObject<DataTable>(obj["childContainer"].ToString());//子批次表格
        DataTable dtCheckPointResult = JsonConvert.DeserializeObject<DataTable>(obj["checkPointResult"].ToString());//检测项列表
        string containerType = obj["containerType"].ToString();//批次类型
        //如果是子序号，则必须勾选子序号或者结果值
        if (containerType == "3" && dtChildContainer.Rows.Count == 0 && dtCheckPointResult.Rows.Count == 0)
        {
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "请选择子序号或者结果值" };
        }
        string strCode = GetCode(dtImage, content);//检测值
        if (string.IsNullOrWhiteSpace(strCode) || strCode.Replace("\\", "/").Contains("/ImageTemp/"))
        {
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "未输入实测值或实测值无效" };
        }
        string stepCheckPointID = obj["stepCheckPointId"].ToString();//检测项ID
        string containerID = obj["containerId"].ToString();//批次ID
        string containerStepWorkReportID = obj["containerStepWorkReportID"].ToString();//报工ID
        Dictionary<string, string> oQuery = new Dictionary<string, string>();

        oQuery.Add("CheckerID", m_UserInfo.EmployeeID.ToString()); //检验员id
        oQuery.Add("CheckPointResultNote", strCode); //检验值源码
        oQuery.Add("CheckPointResultNoteDis", m_CheckPointObj.ConvertTohtml(strCode, usingImg, isUseIP)); //检验值
        oQuery.Add("FactoryID", m_UserInfo.FactoryID);
        oQuery.Add("ContainerStepWorkReportID", containerStepWorkReportID);
        oQuery.Add("StepCheckPointID", stepCheckPointID);
        oQuery.Add("UsingImgPath", usingImg);
        oQuery.Add("ContainerID", containerID);
        if (dtChildContainer.Rows.Count > 0 && dtCheckPointResult.Rows.Count == 0)//如果勾选了子序号，没有勾选结果
        {
            m_CheckPointObj.SaveCheckResultByCheck(oQuery, dtChildContainer);
        }
        else
        {
            //只要勾选了结果值，不管是否勾选子序号，都只更新勾选的结果值
            string sql = string.Format(@"SELECT sp.Stepcheckpointresultid,sp.workresultdocpath,sp.checkresultdocpath
                             FROM stepcheckpointresult sp 
                             WHERE sp.containerstepworkreportid = '{0}' AND sp.stepcheckpointid = '{1}'
                             AND sp.containerid = '{2}' ", containerStepWorkReportID, stepCheckPointID, containerID);
            if (dtCheckPointResult.Rows.Count > 0)
            {
                string checkPointResultIDs = string.Empty;
                dtCheckPointResult.AsEnumerable().ToList().ForEach(p => { checkPointResultIDs += string.Format("'{0}',", p["stepCheckPointResultID"].ToString()); });
                checkPointResultIDs = checkPointResultIDs.TrimEnd(',');
                sql += string.Format(" AND sp.Stepcheckpointresultid IN ({0})", checkPointResultIDs);
            }
            DataTable dtresult = DatabaseHelper.Query_ReturnDatTable(sql);
            if (dtresult.Rows.Count > 0)
            {
                foreach (DataRow item in dtresult.Rows)
                {
                    oQuery["StepCheckPointResultID"] = item["Stepcheckpointresultid"].ToString();
                    oQuery["CheckResultDocPath"] = item["checkresultdocpath"].ToString();
                    if (string.IsNullOrWhiteSpace(oQuery["CheckResultDocPath"]))//如果检验没有上传附件，则改为工人上传的结果
                    {
                        oQuery["CheckResultDocPath"] = dtresult.Rows[0]["workresultdocpath"].ToString();//复制工人上传的附件
                    }
                    m_CheckPointObj.SaveCheckResultByCheck(oQuery);
                }
            }
            else
            {
                //没有结果值，则添加结果
                oQuery.Add("StepCheckPointResultID", null);
                oQuery.Add("CheckResultDocPath", "");
                oQuery.Add("ChildContainerID", "");
                m_CheckPointObj.SaveCheckResultByCheck(oQuery);
            }
        }
        return new uMESProcessResult() { ReturnData = true, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //删除实测值
    uMESProcessResult deleteCheckPointResult(JObject obj)
    {
        string deleType = obj["deleType"].ToString();
        DataTable dtCheckPointResult = JsonConvert.DeserializeObject<DataTable>(obj["checkPointResult"].ToString());
        if (deleType == "1")
        {
            //删除检验实测值
            foreach (DataRow item in dtCheckPointResult.Rows)
            {
                m_CheckPointObj.DeleteCheckResultById(item["StepCheckPointResultID"].ToString(), usingImg);
            }
        }
        if (deleType == "2")
        {
            //删除工人实测值
            foreach (DataRow item in dtCheckPointResult.Rows)
            {
                m_CheckPointObj.DeleteWorkerResultById(item["StepCheckPointResultID"].ToString(), usingImg);
            }
        }
        return new uMESProcessResult() { ReturnData = true, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //导出检测项（检验员）
    uMESProcessResult exportCheckPointItem(JObject obj, HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "导出成功" };
        try
        {
            CurrentUserInfo m_UserInfo = m_Common.GetUserInfo(obj["employeename"].ToString(), "");
            DataTable dtContainer = JsonConvert.DeserializeObject<DataTable>(obj["container"].ToString());
            DataTable dtChildContainer = JsonConvert.DeserializeObject<DataTable>(obj["childContainer"].ToString());
            DataRow activeContainer = dtContainer.Rows[0];
            int[] picCol = new int[] { 8, 13 }; //需要填充图片的列 'update:wangjh 9,14->8,13
            string containerID = activeContainer["containerid"].ToString();
            string stepInfoName = activeContainer["StepInfoName"].ToString(); //工步名
            string stepInfoID = activeContainer["StepInfoID"].ToString(); //工步ID
            string containerName = activeContainer["ContainerName"].ToString(); //批次名
            string workflowStepName = activeContainer["Workflowstepname"].ToString(); //工序
            string containerStepWorkReportID = activeContainer["ContainerStepWorkReportID"].ToString();
            string workerName = activeContainer["FullName"].ToString(); //报工人
            string workQty = activeContainer["Qty"].ToString(); //报工数量
            Dictionary<string, string> oQuery = new Dictionary<string, string>();
            oQuery.Add("ContainerID", containerID);
            oQuery.Add("StepID", activeContainer["WorkFlowStepId"].ToString());
            oQuery.Add("ContainerStepWorkReportID", containerStepWorkReportID);
            if (!string.IsNullOrWhiteSpace(stepInfoID)) //如果包含工步，则添加
            {
                oQuery.Add("StepInfoID", stepInfoID);
                picCol = new[] { 9, 10, 15 }; //update:Wangjh 10, 11, 16->9, 10, 15
            }
            uMESProcessResult oResult = m_CheckPointObj.GetInputStepCheckPointList(oQuery); //获取该工步下的检测项
            DataTable checkPoint = oResult.DBTable;
            DataTable exDt = new DataTable(); //导出数据表
            exDt.Columns.Add("StepCheckPointID"); //检测项ID
            exDt.Columns.Add("ContainerID"); //批次ID
            exDt.Columns.Add("ChildContainerID"); //子序号ID
            exDt.Columns.Add("StepInfoID"); //工步ID
            exDt.Columns.Add("ContainerStepWorkReportID"); //检测项ID
            exDt.Columns.Add("流水卡"); //批次名
            exDt.Columns.Add("流水卡子序号"); //子序号
            exDt.Columns.Add("工序"); //工序
            if (!string.IsNullOrWhiteSpace(stepInfoID))
            {
                exDt.Columns.Add("工步"); //工步名
                exDt.Columns.Add("图纸要求"); //图纸要求
            }
            exDt.Columns.Add("检测项内容"); //生成一张图片后的检测项内容
            exDt.Columns.Add("检测类型"); //检测类型
            exDt.Columns.Add("关键特性标识"); //关键特性标识
            exDt.Columns.Add("报工人"); //报工人
            exDt.Columns.Add("报工数量"); //报工数量
            exDt.Columns.Add("工人实测值"); //工人实测值
            exDt.Columns.Add("检验实测值"); //检验实测值
            List<object> para = new List<object>();
            //带子序号的
            if (dtChildContainer.Rows.Count > 0)
            {
                DataTable checkItemDt = checkPoint.DefaultView.ToTable(true, "StepCheckPointID");
                foreach (DataRow checkItem in checkItemDt.Rows)
                {
                    foreach (DataRow cdr in dtChildContainer.Rows)
                    {
                        string StepCheckPointID = checkItem["StepCheckPointID"].ToString();
                        string childcontainerid = cdr["ChildContainerId"].ToString();
                        DataRow[] checkItemResult = checkPoint.Select("StepCheckPointID=\'" + StepCheckPointID + "\' and childcontainerid=\'" + childcontainerid + "\'");
                        DataRow dr = exDt.NewRow();
                        if (checkItemResult.Length > 0)
                        {
                            dr["StepCheckPointID"] = checkItemResult[0]["StepCheckPointID"].ToString();
                            dr["ContainerID"] = containerID;
                            dr["StepInfoID"] = stepInfoID;
                            dr["ChildContainerID"] = cdr["ChildContainerId"].ToString();
                            dr["ContainerStepWorkReportID"] = containerStepWorkReportID;
                            dr["关键特性标识"] = checkItemResult[0]["KEYCHECKNAME"].ToString();
                            dr["流水卡"] = containerName;
                            dr["工序"] = workflowStepName;
                            dr["流水卡子序号"] = cdr["childContainerName"].ToString();
                            //获取检测项
                            string checkPointNote = checkItemResult[0]["CheckPointNoteDis"].ToString();
                            if (string.IsNullOrWhiteSpace(checkPointNote))
                            {
                                checkPointNote = m_CheckPointObj.ConvertTohtml(checkItemResult[0]["CheckPointNote"].ToString(), usingImg, isUseIP);
                            }
                            dr["检测项内容"] = GetCheckPointNote(context, checkPointNote);
                            //工人检测项
                            string workCheckPointResultNote = checkItemResult[0]["WorkCheckPointResultNoteDis"].ToString();
                            if (string.IsNullOrWhiteSpace(System.Convert.ToString(workCheckPointResultNote)))
                            {
                                workCheckPointResultNote = m_CheckPointObj.ConvertTohtml(checkItemResult[0]["WorkCheckPointResultNote"].ToString(), usingImg, isUseIP);
                            }
                            dr["工人实测值"] = GetCheckPointNote(context, workCheckPointResultNote);
                            //工步
                            if (!string.IsNullOrWhiteSpace(stepInfoName))
                            {
                                string drawingrequire = checkItemResult[0]["drawingrequiredis"].ToString();
                                if (string.IsNullOrWhiteSpace(System.Convert.ToString(drawingrequire)))
                                {
                                    drawingrequire = checkItemResult[0]["drawingrequire"].ToString();
                                }
                                dr["图纸要求"] = GetCheckPointNote(context, drawingrequire);
                                dr["工步"] = stepInfoName;
                            }
                            dr["检测类型"] = checkItemResult[0]["CHECKTYPENAME"].ToString();
                            dr["报工人"] = workerName;
                            dr["报工数量"] = workQty;

                        }
                        else
                        {
                            checkItemResult = checkPoint.Select("StepCheckPointID=\'" + checkItem["StepCheckPointID"].ToString() + "\'");
                            dr["StepCheckPointID"] = checkItemResult[0]["StepCheckPointID"].ToString();
                            dr["ContainerID"] = containerID;
                            dr["ChildContainerID"] = cdr["ChildContainerId"].ToString();
                            dr["StepInfoID"] = stepInfoID;
                            dr["ContainerStepWorkReportID"] = containerStepWorkReportID;
                            dr["关键特性标识"] = checkItemResult[0]["KEYCHECKNAME"].ToString();
                            dr["流水卡"] = containerName;
                            dr["工序"] = workflowStepName;
                            dr["流水卡子序号"] = cdr["childContainerName"].ToString();
                            //获取检测项
                            string checkPointNote = checkItemResult[0]["CheckPointNoteDis"].ToString();
                            if (string.IsNullOrWhiteSpace(checkPointNote))
                            {
                                checkPointNote = m_CheckPointObj.ConvertTohtml(checkItemResult[0]["CheckPointNote"].ToString(), usingImg, isUseIP);
                            }
                            dr["检测项内容"] = GetCheckPointNote(context, checkPointNote);

                            dr["工人实测值"] = "";
                            //工步
                            if (!string.IsNullOrWhiteSpace(stepInfoName))
                            {
                                string drawingrequire = checkItemResult[0]["drawingrequiredis"].ToString();
                                if (string.IsNullOrWhiteSpace(System.Convert.ToString(drawingrequire)))
                                {
                                    drawingrequire = checkItemResult[0]["drawingrequire"].ToString();
                                }
                                dr["图纸要求"] = GetCheckPointNote(context, drawingrequire);
                                dr["工步"] = stepInfoName;
                            }
                            dr["检测类型"] = checkItemResult[0]["CHECKTYPENAME"].ToString();
                            dr["报工人"] = workerName;
                            dr["报工数量"] = workQty;
                        }
                        exDt.Rows.Add(dr);
                    }
                }
            }
            else //不带子序号
            {
                foreach (DataRow row in checkPoint.Rows)
                {
                    DataRow dr = exDt.NewRow();
                    dr["StepCheckPointID"] = row["StepCheckPointID"].ToString();
                    dr["ContainerID"] = containerID;
                    dr["ChildContainerID"] = "";
                    dr["StepInfoID"] = stepInfoID;
                    dr["ContainerStepWorkReportID"] = containerStepWorkReportID;
                    dr["关键特性标识"] = row["KEYCHECKNAME"].ToString();
                    dr["流水卡"] = containerName;
                    dr["工序"] = workflowStepName;
                    dr["流水卡子序号"] = "";
                    //获取检测项
                    string checkPointNote = row["CheckPointNoteDis"].ToString();
                    if (string.IsNullOrWhiteSpace(checkPointNote))
                    {
                        checkPointNote = m_CheckPointObj.ConvertTohtml(row["CheckPointNote"].ToString(), usingImg, isUseIP);
                    }
                    dr["检测项内容"] = GetCheckPointNote(context, checkPointNote);
                    //工人检测项
                    string workCheckPointResultNote = row["WorkCheckPointResultNoteDis"].ToString();
                    if (string.IsNullOrWhiteSpace(workCheckPointResultNote))
                    {
                        workCheckPointResultNote = m_CheckPointObj.ConvertTohtml(row["WorkCheckPointResultNote"].ToString(), usingImg, isUseIP);
                    }
                    dr["工人实测值"] = GetCheckPointNote(context, workCheckPointResultNote);
                    //工步
                    if (!string.IsNullOrWhiteSpace(stepInfoName))
                    {
                        string drawingrequire = row["drawingrequiredis"].ToString();
                        if (string.IsNullOrWhiteSpace(drawingrequire))
                        {
                            drawingrequire = row["drawingrequire"].ToString();
                        }
                        dr["图纸要求"] = GetCheckPointNote(context, drawingrequire);
                        dr["工步"] = stepInfoName;
                    }
                    dr["检测类型"] = row["CHECKTYPENAME"].ToString();
                    dr["报工人"] = workerName;
                    dr["报工数量"] = workQty;
                    exDt.Rows.Add(dr);
                }
            }
            //导出excel
            string fileName = "检验实测值导出(" + m_UserInfo.FullName + ")" + DateTime.Now.ToString("yyyyMMddHHmmddssffff") + ".xls";
            string strPath = context.Request.MapPath(exportPath + "CheckItemTem/");
            if (!Directory.Exists(strPath)) //如果没有目录，创建
            {
                Directory.CreateDirectory(strPath);
            }
            strPath += fileName;
            byte[] ms = uLMS_CommonFunction.DataTableExportToExcel(exDt, null, new int[] { 8, 13 });
            uLMS_CommonFunction.ParseBytesToFile(ms, strPath);
            string url = "http://" + context.Request.Url.Host + context.Request.ApplicationPath + exportPath.Trim('~').Replace("\\", "/") + "CheckItemTem/" + fileName;
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("filename", fileName);
            dic.Add("url", url);
            return new uMESProcessResult() { ReturnData = dic, RowCount = "0", Code = "200", Message = "请求成功" };
        }
        catch (Exception ex)
        {
            return new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "200", Message = "导出失败：" + ex.Message };
        }
    }

    //导入检测项（检验员）
    uMESProcessResult importCheckPointItem(HttpContext context)
    {
        string filePath = "";
        try
        {
            string employeename = context.Request.QueryString["employeename"].ToString();
            if (employeename != "")
            {
                m_UserInfo = m_Common.GetUserInfo(employeename, "");
            }
            var files = context.Request.Files;
            HttpPostedFile file = files.Count > 1 ? files[files.Count - 1] : files[0];
            string IsXls = Path.GetExtension(file.FileName);
            string fileName = Path.GetFileNameWithoutExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssffff") + IsXls;
            string fileBasePath = importPath + "CheckItemTem/";
            if (!Directory.Exists(context.Server.MapPath(fileBasePath))) //如果没有目录，创建
            {
                Directory.CreateDirectory(context.Server.MapPath(fileBasePath));
            }
            filePath = context.Server.MapPath(fileBasePath + fileName);
            file.SaveAs(filePath);//保存文件

            IWorkbook workbook = uLMS_CommonFunction.GetWorkbookObj(filePath);
            if (workbook == null)
            {
                return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "解析出错" };
            }
            DeleteUploadedFile(filePath); //删除上传的文件
            DataTable dt = new DataTable();
            dt = uLMS_CommonFunction.ExcelImportToDataTable(workbook);
            ExcuteEntity exuteEntity = new ExcuteEntity("stepcheckpointresult", ExcuteEntity.ExcuteTypeEnum.selectAll);
            exuteEntity.WhereFileds = new List<FieldEntity>() { new FieldEntity("containerid", dt.Rows[0]["ContainerID"].ToString(), FieldEntity.FieldTypeEnum.Str) };
            DataTable dtContainerResult = DatabaseHelper.QueryDataByEntity(exuteEntity);//(new ExcuteEntity("stepcheckpointresult", ExcuteEntity.ExcuteTypeEnum.selectAll));
            string sqlContainer = "SELECT c.containername,c.containertype FROM containercurrentinfo c WHERE c.containerid = '{0}'";
            DataTable dtContainer = new DataTable();
            DataTable dtChildContainer = new DataTable();
            //填写检测项
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                string strCode = row["检验实测值"].ToString(); //检验实测值
                string stepCheckPointID = row["StepCheckPointID"].ToString(); //检测项ID
                string containerName = row["流水卡"].ToString(); //流水卡
                string containerID = row["ContainerID"].ToString();
                string stepInfoID = row["StepInfoID"].ToString();
                string containerStepWorkReportID = row["ContainerStepWorkReportID"].ToString(); //报工ID
                dtContainer = DatabaseHelper.Query_ReturnDatTable(string.Format(sqlContainer, containerID));
                //判断是否有报工
                if (string.IsNullOrWhiteSpace(containerStepWorkReportID))
                {
                    string msg = string.Format("导入成功：{0}条，第{1}行ContainerStepWorkReportID为空", (i).ToString(), (i + 1).ToString());
                    return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
                }
                //判断是否有该批次
                if (string.IsNullOrWhiteSpace(containerID) || dtContainer.Rows.Count == 0)
                {
                    string msg = string.Format("导入成功：{0}条，第{1}行批次未找到", (i).ToString(), (i + 1).ToString());
                    return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
                }
                string childContainerID = row["ChildContainerID"].ToString(); //子序号ID
                dtChildContainer = m_CommonObj.GetContainerInfoByPerContianerID2(containerID);
                //如果未找到子序号ID，则结束
                if (dtContainer.Rows[0]["containertype"].ToString() == "3" && !dt.Columns.Contains("工步") && (string.IsNullOrWhiteSpace(childContainerID) || dtChildContainer.AsEnumerable().Where(p => p["containerid"].ToString() == childContainerID).Count() == 0))
                {
                    string msg = string.Format("导入成功：{0}条，第{1}行的子批次为空或未找到", (i).ToString(), (i + 1).ToString());
                    return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
                }
                //判断工步
                if (dt.Columns.Contains("工步") && string.IsNullOrWhiteSpace(stepInfoID))
                {
                    string msg = string.Format("导入成功：{0}条，第{1}行工步未找到", (i).ToString(), (i + 1).ToString());
                    return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
                }
                Dictionary<string, string> para = new Dictionary<string, string>();
                para.Add("ContainerID", containerID);
                para.Add("FactoryID", m_UserInfo.FactoryID);
                para.Add("StepCheckPointID", stepCheckPointID);
                para.Add("ChildContainerID", childContainerID);
                para.Add("ContainerStepWorkReportID", containerStepWorkReportID);
                para.Add("StepInfoID", stepInfoID);
                para.Add("CheckerID", m_UserInfo.EmployeeID.ToString()); //检验员id
                para.Add("CheckPointResultNote", strCode); //检验值源码
                para.Add("CheckPointResultNoteDis", strCode); //检验值
                para.Add("StepCheckPointResultID", null); //结果ID
                //查询是否存在检测结果
                string selectStr = string.Format("stepcheckpointid='{0}' and containerstepworkreportid='{1}'", stepCheckPointID, containerStepWorkReportID);
                if (!string.IsNullOrWhiteSpace(childContainerID))
                {
                    selectStr += " and childcontainerid='" + childContainerID + "'";
                }
                DataRow[] drs = dtContainerResult.Select(selectStr);
                if (drs.Length > 0) //存在，则更新结果ID
                {
                    para["StepCheckPointResultID"] = drs[0]["stepcheckpointresultid"].ToString();
                    para["CheckResultDocPath"] = drs[0]["checkresultdocpath"].ToString();
                    if (string.IsNullOrWhiteSpace(para["CheckResultDocPath"]))
                    {
                        para["CheckResultDocPath"] = drs[0]["workresultdocpath"].ToString(); //将工人附件赋值给检验附件
                    }
                }

                //保存数据
                if (!(m_CheckPointObj.SaveCheckResultByCheck(para)))
                {
                    string msg = string.Format("导入成功：{0}条，第{1}行数据保存时报错", (i).ToString(), (i + 1).ToString());
                    return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
                }
            }
        }
        catch (Exception ex)
        {
            DeleteUploadedFile(filePath);
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "上传失败：" + ex.Message };
        }
        return new uMESProcessResult() { ReturnData = true, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //一键确认前校验
    uMESProcessResult copyWorkerInputValidate(JObject obj)
    {
        string sql = @"
SELECT sp.containerid,sp.containerstepworkreportid,sp.workcheckpointresultnote,sp.workcheckpointresultnotedis 
FROM stepcheckpointresult sp
WHERE sp.containerstepworkreportid = '{0}' AND sp.workcheckpointresultnotedis IS NOT NULL";
        DataTable dtResult = DatabaseHelper.Query_ReturnDatTable(string.Format(sql, obj["containerstepworkreportid"].ToString()));
        foreach (DataColumn col in dtResult.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtResult, RowCount = dtResult.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //一键确认
    uMESProcessResult copyWorkerInputResultValue(JObject obj)
    {
        string containerID = obj["containerId"].ToString();//批次ID
        string containerStepWorkReportID = obj["containerStepWorkReportID"].ToString();//报工ID
        CurrentUserInfo m_UserInfo = m_Common.GetUserInfo(obj["employeename"].ToString(), "");
        //更新数据
        string sql = string.Format(@"UPDATE stepcheckpointresult sp SET sp.checkpointresultnote = sp.workcheckpointresultnote,sp.checkpointresultnotedis_b = sp.workcheckpointresultnotedis_b,
                                    sp.checkpointresultnotedis = sp.workcheckpointresultnotedis,sp.checkerid = '{0}',sp.checkdate = SYSDATE,
                                    sp.lastchangedate = SYSDATE,sp.tempdealfail = 0
                                    WHERE sp.containerid = '{1}' AND sp.containerstepworkreportid = '{2}'
                                    AND sp.workcheckpointresultnotedis IS NOT NULL AND sp.checkpointresultnotedis IS NULL",
                                    m_UserInfo.EmployeeID.ToString(), containerID, containerStepWorkReportID);
        DatabaseHelper.ExecuteSql(sql);
        return new uMESProcessResult() { ReturnData = true, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //推送给三坐标检测记录
    uMESProcessResult sendToThreeCoordinateRecord(JObject obj)
    {
        CurrentUserInfo m_UserInfo = m_Common.GetUserInfo(obj["employeename"].ToString(), "");
        DataTable dtCheckPoint = JsonConvert.DeserializeObject<DataTable>(obj["checkPoint"].ToString());
        Dictionary<string, string> dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(obj["mainParam"].ToString());
        //验证是否已有记录数据
        string stepCheckPointIDs = string.Empty;
        List<Dictionary<string, object>> checkPointIDList = new List<Dictionary<string, object>>();
        dtCheckPoint.AsEnumerable().ToList().ForEach(p =>
        {
            stepCheckPointIDs += string.Format("'{0}',", p["StepCheckPointID"].ToString());
            checkPointIDList.Add(new Dictionary<string, object> { { "stepCheckPointId", p["StepCheckPointID"].ToString() } });
        });
        stepCheckPointIDs = stepCheckPointIDs.Trim(',');
        string sql = string.Format("SELECT 1 FROM SendThreeCoordinateRecord s WHERE s.stepcheckpointid IN ({0})", stepCheckPointIDs);
        if (DatabaseHelper.GetSingle(sql) != null)
        {
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "已存在相同的检测项" };
        }
        //查询派工记录
        if (dic.ContainsKey("containerstepdispatchid"))
        {
            sql = string.Format("SELECT csd.qty,csd.containerstepdispatchid FROM containerstepdispatch csd WHERE csd.containerstepdispatchid = '{0}'", dic["containerstepdispatchid"]);
        }
        else
        {
            //如果不包含派工ID，则通过报工ID来查询（主要针对检验录入）
            sql = string.Format(@"SELECT csw.qty,csd.containerstepdispatchid FROM containerstepworkreport csw
            LEFT JOIN containerstepdispatch csd ON csd.containerstepdispatchid = csw.containerstepdispatchid
            WHERE csw.containerstepworkreportid = '{0}'", dic["containerstepworkreportid"]);
        }
        DataTable dtDis = DatabaseHelper.Query_ReturnDatTable(sql);
        if (dtDis.Rows.Count == 0)
        {
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "未找到对应的派工数据" };
        }
        if (!m_CheckPointObj.UpdateStepCheckPointValue(checkPointIDList))//调用更新基准值方法
        {
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "更新基准值失败" };
        }
        List<ExcuteEntity> insertList = new List<ExcuteEntity>();
        string id2 = Guid.NewGuid().ToString();
        foreach (DataRow item in dtCheckPoint.Rows)
        {
            //插入数据库
            ExcuteEntity exuteEntity = new ExcuteEntity("SendThreeCoordinateRecord", ExcuteEntity.ExcuteTypeEnum.insert);
            List<FieldEntity> excuteFieldList = new List<FieldEntity>();
            excuteFieldList.Add(new FieldEntity("Id", Guid.NewGuid().ToString(), FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Id2", id2, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Containerid", dic["containerid"], FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Workflowstepid", dic["workflowstepid"], FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Containername", dic["containername"], FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Workflowstepname", dic["workflowstepname"], FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Containerstepdispatchid", dtDis.Rows[0]["containerstepdispatchid"].ToString(), FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Stepcheckpointid", item["StepCheckPointID"].ToString(), FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("CreateEmployeeId", m_UserInfo.EmployeeID, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("CreateDate", DateTime.Now, FieldEntity.FieldTypeEnum.DateTime));
            excuteFieldList.Add(new FieldEntity("ApplyFactoryCode", m_UserInfo.FactoryCode, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("IsSend", "0", FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("IsUse", "0", FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Qty", int.Parse(dtDis.Rows[0]["QTY"].ToString()), FieldEntity.FieldTypeEnum.Numer));
            excuteFieldList.Add(new FieldEntity("FactoryID", m_UserInfo.FactoryID, FieldEntity.FieldTypeEnum.Str));
            exuteEntity.ExcuteFileds = excuteFieldList;
            insertList.Add(exuteEntity);
        }
        bool isSuccess = DatabaseHelper.ExecuteDataByEntitys(insertList);
        return new uMESProcessResult() { ReturnData = isSuccess, RowCount = "0", Code = "200", Message = isSuccess ? "保存成功" : "保存失败" };
    }

    //上传实测值附件
    uMESProcessResult saveCheckPointResultDocFile(HttpContext context)
    {
        string fileComPath = "";
        try
        {
            string uploadType = context.Request["uploadType"].ToString();
            DataTable dtStepCheckPointResult = JsonConvert.DeserializeObject<DataTable>(context.Request["checkPointResult"].ToString());//实测值结果
            var files = context.Request.Files;
            HttpPostedFile file = files.Count > 1 ? files[files.Count - 1] : files[0];
            string fileExtension = Path.GetExtension(file.FileName);
            string fileName = Path.GetFileNameWithoutExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssffff") + fileExtension;
            string filePath = "/UsingCheckImage/CheckResultDoc/";
            string fileBasePath = context.Server.MapPath(context.Request.ApplicationPath + filePath);
            if (!Directory.Exists(fileBasePath)) //如果没有目录，创建
            {
                Directory.CreateDirectory(fileBasePath);
            }
            fileComPath = fileBasePath + fileName;
            file.SaveAs(fileComPath);//保存文件
            //保存数据
            string docpath = uploadType == "1" ? "workresultdocpath" : "checkresultdocpath";
            string upLoadSql = "update stepcheckpointresult sp set sp.{0} = '{1}' where sp.stepcheckpointresultid = '{2}'";
            System.Collections.ArrayList list = new System.Collections.ArrayList();
            foreach (DataRow item in dtStepCheckPointResult.Rows)
            {
                //更新实测值结果表
                list.Add(string.Format(upLoadSql, docpath, filePath + fileName, item["stepcheckpointresultid"].ToString()));
            }
            if (list.Count > 0)
            {
                DatabaseHelper.ExecuteSqlTran(list);
            }
        }
        catch (Exception ex)
        {
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "上传出错，原因：" + ex.Message };
        }
        return new uMESProcessResult() { ReturnData = true, RowCount = "0", Code = "200", Message = "上传成功" };
    }

    //保存工人实测值
    uMESProcessResult saveCheckResultByWorker(JObject obj, HttpContext context)
    {
        string content = obj["content"].ToString();
        string opertype = obj["opertype"].ToString();//操作类型
        string containerID = obj["containerid"].ToString();//批次ID
        string containertype = obj["containertype"].ToString();//批次类型
        string stepcheckpointid = obj["stepcheckpointid"].ToString();//检测项ID
        CurrentUserInfo m_UserInfo = m_Common.GetUserInfo(obj["employeename"].ToString(), "");

        DataTable dtImage = (DataTable)context.Session["dtImage"];
        DataTable dtChildContainer = JsonConvert.DeserializeObject<DataTable>(obj["childContainer"].ToString());//子批次
        DataTable dtStepCheckPoint = JsonConvert.DeserializeObject<DataTable>(obj["stepCheckPointList"].ToString());//检测项列表
        DataTable dtCheckPointResult = JsonConvert.DeserializeObject<DataTable>(obj["checkPointResultList"].ToString());//检测项结果

        string strCode = GetCode(dtImage, content);//检测值

        if (string.IsNullOrWhiteSpace(strCode) || strCode.Replace("\\", "/").Contains("/ImageTemp/"))
        {
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "未输入实测值或实测值无效" };
        }

        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("WORKERID", m_UserInfo.EmployeeID);
        dic.Add("WORKCHECKPOINTRESULTNOTE", strCode);
        dic.Add("WORKCHECKPOINTRESULTNOTEDIS", m_CheckPointObj.ConvertTohtml(strCode, usingImg, isUseIP));
        dic.Add("ContainerID", containerID);
        dic.Add("ChildContainerID", "");
        dic.Add("FactoryID", m_UserInfo.FactoryID);
        dic.Add("IsBatch", "1");//可批量添加结果值
        if (opertype == "add")
        {
            if (containertype == "3" && dtChildContainer.Rows.Count == 0)
            {
                return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "请选择子工序" };
            }

            if (dtStepCheckPoint.Rows.Count == 0)
            {
                return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "请选择检测项" };
            }
            dic.Add("StepCheckPointID", "");
            string stepCheckPointIDs = string.Empty;
            dtStepCheckPoint.AsEnumerable().ToList().ForEach(p =>
            {
                stepCheckPointIDs += string.Format("'{0}',", p["StepCheckPointID"].ToString());
            });
            stepCheckPointIDs = stepCheckPointIDs.TrimEnd(',');
            string sql = @"select 1 from stepcheckpointresult sr where sr.stepcheckpointid IN ({0}) and sr.workerid != '{1}' and sr.containerid = '{2}'";
            if (dtChildContainer.Rows.Count > 0)
            {
                string childContainerIDs = string.Empty;//子序号ID
                dtChildContainer.AsEnumerable().ToList().ForEach(p => { childContainerIDs += string.Format("'{0}',", p["containerID"].ToString()); });
                childContainerIDs = childContainerIDs.TrimEnd(',');
                sql += string.Format(" and sr.childcontainerid in ({0})", childContainerIDs);
            }
            if (DatabaseHelper.GetSingle(string.Format(sql, stepCheckPointIDs, m_UserInfo.EmployeeID, containerID)) != null)
            {
                return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "存在其他工人录入" };
            }
            if (dtChildContainer.Rows.Count == 0) //没带子序号的数据保存
            {
                foreach (DataRow item in dtStepCheckPoint.Rows)
                {
                    dic["StepCheckPointID"] = item["StepCheckPointID"].ToString();
                    sql = string.Format("SELECT 1 FROM stepcheckpointresult sr WHERE sr.stepcheckpointid = '{0}' AND sr.containerid = '{1}'", dic["StepCheckPointID"], containerID);
                    int inputNum = int.Parse(item["inputNum"].ToString());//检测项的录入次数
                    int resNum = DatabaseHelper.Query_ReturnDatTable(sql).Rows.Count;//录入结果的次数
                    for (int i = resNum; i < inputNum; i++)
                    {
                        m_CheckPointObj.SaveCheckResultByWorker(dic);
                    }
                }
            }
            else
            {
                foreach (DataRow item in dtStepCheckPoint.Rows)
                {
                    dic["StepCheckPointID"] = item["StepCheckPointID"].ToString();
                    foreach (DataRow itemCh in dtChildContainer.Rows)
                    {
                        dic["ChildContainerID"] = itemCh["ContainerID"].ToString();
                        sql = string.Format("SELECT 1 FROM stepcheckpointresult sr WHERE sr.stepcheckpointid = '{0}' AND sr.containerid = '{1}' AND sr.childcontainerid = '{2}'",
                            dic["StepCheckPointID"], containerID, dic["ChildContainerID"]);
                        int inputNum = int.Parse(item["inputNum"].ToString());//检测项的录入次数
                        int resNum = DatabaseHelper.Query_ReturnDatTable(sql).Rows.Count;//录入结果的次数
                        for (int i = resNum; i < inputNum; i++)
                        {
                            m_CheckPointObj.SaveCheckResultByWorker(dic);
                        }
                    }
                }
            }
        }

        //保存
        if (opertype == "update")
        {
            dic.Add("StepCheckPointID", stepcheckpointid);
            foreach (DataRow item in dtCheckPointResult.Rows)
            {
                dic["StepCheckPointResultID"] = item["StepCheckPointResultID"].ToString();
                dic["UsingImgPath"] = usingImg;
                m_CheckPointObj.SaveCheckResultByWorker(dic);
            }
        }
        return new uMESProcessResult() { ReturnData = true, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //导出检测项(工人)
    uMESProcessResult exportCheckPointFileByWorker(JObject obj, HttpContext context)
    {
        CurrentUserInfo m_UserInfo = m_Common.GetUserInfo(obj["employeename"].ToString(), "");
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "保存成功" };
        DataTable dtContainer = JsonConvert.DeserializeObject<DataTable>(obj["container"].ToString());//主批次
        DataTable dtChildContainer = JsonConvert.DeserializeObject<DataTable>(obj["childContainer"].ToString());//子序号批次
        int[] picCol = new int[] { 7 }; //需要填充图片的列,update:Wangjh 8->7
        string containerID = dtContainer.Rows[0]["ContainerID"].ToString();
        string stepInfoName = ""; //工步名
        string stepInfoID = ""; //工步ID
        string containerName = dtContainer.Rows[0]["ContainerName"].ToString(); //批次名
        string workflowStepName = dtContainer.Rows[0]["Workflowstepname"].ToString(); //工序
        DataTable exDt = new DataTable();
        exDt.Columns.Add("StepCheckPointID");//检测项ID
        exDt.Columns.Add("ContainerID");//批次ID
        exDt.Columns.Add("ChildContainerID");//子序号ID
        exDt.Columns.Add("StepInfoID");//工步ID
        exDt.Columns.Add("流水卡"); //批次名
        exDt.Columns.Add("流水卡子序号"); //子序号
        exDt.Columns.Add("工序");//工序
        if (!string.IsNullOrWhiteSpace(stepInfoName)) //如果有工步，则添加
        {
            exDt.Columns.Add("工步"); //工步名
            exDt.Columns.Add("图纸要求"); //图纸要求
            picCol = new[] { 8, 9 };
        }
        exDt.Columns.Add("检测项内容"); //导出后的要求值
        exDt.Columns.Add("检测类型"); //检测类型
        exDt.Columns.Add("关键特性标识"); //关键特性标识
        exDt.Columns.Add("工人实测值"); //工人实测值
        DataTable checkPoint = m_CheckPointObj.GetContainerCheckPointList(dtContainer.Rows[0]["workflowstepid"].ToString(), "");
        List<object> para = new List<object>();
        if (dtChildContainer.Rows.Count > 0)
        {
            foreach (DataRow cdr in dtChildContainer.Rows)
            {
                foreach (DataRow row in checkPoint.Rows)
                {
                    DataRow dr = exDt.NewRow();
                    dr["StepCheckPointID"] = row["StepCheckPointID"];
                    dr["ContainerID"] = containerID;
                    dr["ChildContainerID"] = cdr["ContainerID"].ToString();
                    dr["StepInfoID"] = stepInfoID;
                    dr["关键特性标识"] = row["KeyCheckName"];
                    dr["流水卡"] = containerName;
                    dr["工序"] = workflowStepName;
                    dr["流水卡子序号"] = cdr["ContainerName"].ToString();
                    string checkPointNote = row["CheckPointNoteDis"].ToString();
                    if (string.IsNullOrWhiteSpace(checkPointNote))
                    {
                        checkPointNote = m_CheckPointObj.ConvertTohtml(row["CheckPointNote"].ToString(), usingImg, isUseIP);
                    }
                    dr["检测项内容"] = GetCheckPointNote(context, checkPointNote);
                    if (!string.IsNullOrWhiteSpace(stepInfoName)) //如果有工步，则添加
                    {
                        string drawingrequire = row["drawingrequiredis"].ToString();
                        if (string.IsNullOrWhiteSpace(drawingrequire))
                        {
                            drawingrequire = row["drawingrequire"].ToString();
                        }
                        dr["图纸要求"] = GetCheckPointNote(context, drawingrequire);
                        dr["工步"] = stepInfoName;
                    }
                    dr["检测类型"] = row["CheckTypeName"];
                    exDt.Rows.Add(dr);
                }
            }
        }
        else
        {
            foreach (DataRow row in checkPoint.Rows)
            {
                DataRow dr = exDt.NewRow();
                dr["StepCheckPointID"] = row["StepCheckPointID"];
                dr["ContainerID"] = containerID;
                dr["StepInfoID"] = stepInfoID;
                dr["ChildContainerID"] = "";
                dr["关键特性标识"] = row["KeyCheckName"];
                dr["流水卡"] = containerName;
                dr["工序"] = workflowStepName;
                dr["流水卡子序号"] = "";
                string checkPointNote = row["CheckPointNoteDis"].ToString();
                if (string.IsNullOrWhiteSpace(checkPointNote))
                {
                    checkPointNote = m_CheckPointObj.ConvertTohtml(row["CheckPointNote"].ToString(), usingImg, isUseIP);
                }
                dr["检测项内容"] = GetCheckPointNote(context, checkPointNote);
                if (!string.IsNullOrWhiteSpace(stepInfoName)) //如果有工步，则添加
                {
                    string drawingrequire = row["drawingrequiredis"].ToString();
                    if (string.IsNullOrWhiteSpace(drawingrequire))
                    {
                        drawingrequire = row["drawingrequire"].ToString();
                    }
                    dr["图纸要求"] = GetCheckPointNote(context, drawingrequire);
                    dr["工步"] = stepInfoName;
                }
                dr["检测类型"] = row["CheckTypeName"];
                exDt.Rows.Add(dr);
            }
        }
        //导出excel
        string fileName = "工人实测值导出(" + m_UserInfo.FullName + ")" + DateTime.Now.ToString("yyyyMMddHHmmddssffff") + ".xls";
        string strPath = context.Request.MapPath(exportPath + "CheckItemTem/");
        if (!Directory.Exists(strPath)) //如果没有目录，创建
        {
            Directory.CreateDirectory(strPath);
        }
        strPath += fileName;
        byte[] ms = uLMS_CommonFunction.DataTableExportToExcel(exDt, null, picCol);
        uLMS_CommonFunction.ParseBytesToFile(ms, strPath);
        string url = "http://" + context.Request.Url.Host + context.Request.ApplicationPath + exportPath.Trim('~').Replace("\\", "/") + "CheckItemTem/" + fileName;
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("filename", fileName);
        dic.Add("url", url);
        return new uMESProcessResult() { ReturnData = dic, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //导入检测项（工人）
    uMESProcessResult importWorkerCheckPointItem(HttpContext context)
    {
        string filePath = "";
        try
        {
            string employeename = context.Request.QueryString["employeename"].ToString();
            if (employeename != "")
            {
                m_UserInfo = m_Common.GetUserInfo(employeename, "");
            }
            var files = context.Request.Files;
            HttpPostedFile file = files.Count > 1 ? files[files.Count - 1] : files[0];
            string IsXls = Path.GetExtension(file.FileName);
            string fileName = Path.GetFileNameWithoutExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssffff") + IsXls;
            string fileBasePath = importPath + "CheckItemTem/";
            if (!Directory.Exists(context.Server.MapPath(fileBasePath))) //如果没有目录，创建
            {
                Directory.CreateDirectory(context.Server.MapPath(fileBasePath));
            }
            filePath = context.Server.MapPath(fileBasePath + fileName);
            file.SaveAs(filePath);//保存文件

            IWorkbook workbook = uLMS_CommonFunction.GetWorkbookObj(filePath);
            if (workbook == null)
            {
                return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "解析出错" };
            }
            DeleteUploadedFile(filePath); //删除上传的文件
            DataTable dt = new DataTable();
            dt = uLMS_CommonFunction.ExcelImportToDataTable(workbook);
            string sqlContainer = "SELECT c.containername,c.containertype FROM containercurrentinfo c WHERE c.containerid = '{0}'";
            DataTable dtContainer = new DataTable();
            DataTable dtChildContainer = new DataTable();
            //填写检测项
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                string containerID = row["ContainerID"].ToString();
                string stepInfoID = row["StepInfoID"].ToString();
                dtContainer = DatabaseHelper.Query_ReturnDatTable(string.Format(sqlContainer, containerID));
                //判断是否有该批次
                if (string.IsNullOrWhiteSpace(containerID) || dtContainer.Rows.Count == 0)
                {
                    string msg = string.Format("导入成功：{0}条，第{1}行的批次为空或未找到", (i).ToString(), (i + 1).ToString());
                    return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
                }
                string childContainerID = row["ChildContainerID"].ToString(); //子序号ID
                dtChildContainer = m_CommonObj.GetContainerInfoByPerContianerID2(containerID);
                //如果未找到子序号ID，则结束
                if (dtContainer.Rows[0]["containertype"].ToString() == "3" && !dt.Columns.Contains("工步") && (string.IsNullOrWhiteSpace(childContainerID) || dtChildContainer.AsEnumerable().Where(p => p["containerid"].ToString() == childContainerID).Count() == 0))
                {
                    string msg = string.Format("导入成功：{0}条，第{1}行的子批次为空或未找到", (i).ToString(), (i + 1).ToString());
                    return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
                }
                //如果未找到工步
                if (dt.Columns.Contains("工步") && string.IsNullOrWhiteSpace(stepInfoID))
                {
                    string msg = string.Format("导入成功：{0}条，第{1}行的工步为空或未找到", (i).ToString(), (i + 1).ToString());
                    return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
                }
                Dictionary<string, string> para = new Dictionary<string, string>();
                para.Add("WORKERID", m_UserInfo.EmployeeID.ToString());
                para.Add("WORKCHECKPOINTRESULTNOTE", row["工人实测值"].ToString());
                para.Add("WORKCHECKPOINTRESULTNOTEDIS", row["工人实测值"].ToString());
                para.Add("ContainerID", containerID);
                para.Add("FactoryID", m_UserInfo.FactoryID);
                para.Add("StepCheckPointID", row["StepCheckPointID"].ToString());
                para.Add("ChildContainerID", childContainerID);
                para.Add("StepInfoID", stepInfoID);
                //保存数据
                string strMsg = "";
                if (!(m_CheckPointObj.SaveCheckPointResultByImport(para, 1, ref strMsg)))
                {
                    string msg = string.Format("导入成功：{0}条，第{1}行数据保存时报错", (i).ToString(), (i + 1).ToString());
                    return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
                }
            }
        }
        catch (Exception ex)
        {
            DeleteUploadedFile(filePath);
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "上传失败：" + ex.Message };
        }
        return new uMESProcessResult() { ReturnData = true, RowCount = "0", Code = "200", Message = "上传成功" };
    }

    //查询工人录入实测值
    uMESProcessResult getWorkerInputValues(JObject obj)
    {
        string sql = @"
SELECT scr.workcheckpointresultnote,scr.checkpointresultnote,sc.basevalue,sc.floorfloat,sc.ceilfloat,sc.bubblenumber
FROM stepcheckpoint sc
LEFT JOIN stepcheckpointresult scr ON scr.stepcheckpointid = sc.stepcheckpointid
WHERE scr.containerid = '{0}' AND scr.containerstepworkreportid = '{1}'";
        sql = string.Format(sql, obj["containerid"].ToString(), obj["containerstepworkreportid"].ToString());
        DataTable dtResult = DatabaseHelper.Query_ReturnDatTable(sql);
        foreach (DataColumn col in dtResult.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtResult, RowCount = dtResult.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    uMESProcessResult getInputCheckPointResult(JObject obj)
    {
        string sql = @"
SELECT sp.stepcheckpointid,spr.containerid,spr.createdate,spr.workcheckpointresultnotedis,
        row_number () OVER (PARTITION BY sp.stepcheckpointid,spr.containerid ORDER BY spr.createdate DESC) as rn
FROM stepcheckpoint sp
LEFT JOIN stepcheckpointresult spr ON spr.stepcheckpointid = sp.stepcheckpointid AND spr.containerid = '{0}'
WHERE sp.workflowstepid = '{1}'";
        sql = string.Format(sql, obj["containerid"].ToString(), obj["workflowstepid"].ToString());
        DataTable dtResult = DatabaseHelper.Query_ReturnDatTable(sql);
        foreach (DataColumn col in dtResult.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtResult, RowCount = dtResult.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }
}